package com.health.tablebean.webservice;

import android.content.Context;
import android.text.TextUtils;

import com.health.tablebean.ARCHIVE_BASEINFO;
import com.health.viewscontrols.NovaApplication;
import com.health.db.FDbManager;
import com.health.tablebean.CD_MENTALDISEASE_BASEINFO;
import com.health.tools.GlobalConts;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 田相伟 on 2018/3/31.
 * 严重精神障碍患者-基本信息
 */

public class JsjbBaseInfo {
    private String mainSymptom;//既往主要症状
    private int lightAffray;//轻度滋事次数
    private int causeTrouble;//肇事次数
    private int causeAccident;//肇祸次数
    private int attemptedSuicide;//自杀未遂次数
    private String pasttreatEffect;//创建时间
    private int res5;//其他危害行为次数
    private String createorg;//创建机构
    private String res2;//危险行为：无；DM01-11_1

    private String otherSymptom;//既往主要症状其他
    private String guardAddress;//监护人住址
    private String relationship;//与患者关系
    private String commitDutyname;//辖区村(居)委会联系人
    private String commitDutyphone;//辖区村(居)委会电话
    private String knowSignname;//知情同意签字
    private String knowSigndate;//签字时间
    private String friststartAge;//初次发病时间
    private String fristavoidCode;//首次抗精神病药治疗时间
    private String specialhospNum;//曾住精神专科医院/综合医院精神专科
    private String mentaldiseaseName;//目前诊断情况诊断
    private String sureHospital;//确诊医院
    private String economyCode;//经济状况
    private String perficialAdvise;//专科医生的意见(如果有请记录)
    private String cardid;//身份证号
    private String wzd;//完整度

    private String res4;//就业情况
    private String createtime;//创建时间
    private String creater;//创建人
    private String qdqxz;//缺项值
    private int selfInjury;//自伤
    private String res3;//户别 城镇:DM01-26_1 农村:DM01-26_2
    private String lockCode;//既往关锁情况 无关锁:DM01-75_1关锁:DM01-75_2 关锁已解除:DM01-75_3

    private String guardName;//监护人姓名
    private String guardphone;//监护人电话
    private String knownCode;//知情同意同意 参加 管理:DM01-78_1不同意参加管理:DM01-78_2

    private String clinicCode;//门诊未治:DM01-79_1间断门诊治疗:DM01-79_3连续门诊治疗:DM01-79_3

    private String sureDate;//确诊日期
    private String inputName;//医生签名
    private String inputTime;//填表日期

    private String fromType = "2";// 数据来源；空为公卫，‘1’为手提箱，‘2’为PAD
    private String updatetime;//修改时间
    private String updateorg;

    public String getFromType() {
        return fromType;
    }

    public void setFromType(String fromType) {
        this.fromType = fromType;
    }

    public String getUpdatetime() {
        return updatetime;
    }

    public void setUpdatetime(String updatetime) {
        this.updatetime = updatetime;
    }

    public String getUpdateorg() {
        return updateorg;
    }

    public void setUpdateorg(String updateorg) {
        this.updateorg = updateorg;
    }

    public String getMainSymptom() {
        return mainSymptom;
    }

    public void setMainSymptom(String mainSymptom) {
        this.mainSymptom = mainSymptom;
    }

    public int getLightAffray() {
        return lightAffray;
    }

    public void setLightAffray(int lightAffray) {
        this.lightAffray = lightAffray;
    }

    public int getCauseTrouble() {
        return causeTrouble;
    }

    public void setCauseTrouble(int causeTrouble) {
        this.causeTrouble = causeTrouble;
    }

    public int getCauseAccident() {
        return causeAccident;
    }

    public void setCauseAccident(int causeAccident) {
        this.causeAccident = causeAccident;
    }

    public int getAttemptedSuicide() {
        return attemptedSuicide;
    }

    public void setAttemptedSuicide(int attemptedSuicide) {
        this.attemptedSuicide = attemptedSuicide;
    }

    public String getPasttreatEffect() {
        return pasttreatEffect;
    }

    public void setPasttreatEffect(String pasttreatEffect) {
        this.pasttreatEffect = pasttreatEffect;
    }

    public int getRes5() {
        return res5;
    }

    public void setRes5(int res5) {
        this.res5 = res5;
    }

    public String getCreateorg() {
        return createorg;
    }

    public void setCreateorg(String createorg) {
        this.createorg = createorg;
    }

    public String getRes2() {
        return res2;
    }

    public void setRes2(String res2) {
        this.res2 = res2;
    }

    public String getOtherSymptom() {
        return otherSymptom;
    }

    public void setOtherSymptom(String otherSymptom) {
        this.otherSymptom = otherSymptom;
    }

    public String getGuardAddress() {
        return guardAddress;
    }

    public void setGuardAddress(String guardAddress) {
        this.guardAddress = guardAddress;
    }

    public String getRelationship() {
        return relationship;
    }

    public void setRelationship(String relationship) {
        this.relationship = relationship;
    }

    public String getCommitDutyname() {
        return commitDutyname;
    }

    public void setCommitDutyname(String commitDutyname) {
        this.commitDutyname = commitDutyname;
    }

    public String getCommitDutyphone() {
        return commitDutyphone;
    }

    public void setCommitDutyphone(String commitDutyphone) {
        this.commitDutyphone = commitDutyphone;
    }

    public String getKnowSignname() {
        return knowSignname;
    }

    public void setKnowSignname(String knowSignname) {
        this.knowSignname = knowSignname;
    }

    public String getKnowSigndate() {
        return knowSigndate;
    }

    public void setKnowSigndate(String knowSigndate) {
        this.knowSigndate = knowSigndate;
    }

    public String getFriststartAge() {
        return friststartAge;
    }

    public void setFriststartAge(String friststartAge) {
        this.friststartAge = friststartAge;
    }

    public String getFristavoidCode() {
        return fristavoidCode;
    }

    public void setFristavoidCode(String fristavoidCode) {
        this.fristavoidCode = fristavoidCode;
    }

    public String getSpecialhospNum() {
        return specialhospNum;
    }

    public void setSpecialhospNum(String specialhospNum) {
        this.specialhospNum = specialhospNum;
    }

    public String getMentaldiseaseName() {
        return mentaldiseaseName;
    }

    public void setMentaldiseaseName(String mentaldiseaseName) {
        this.mentaldiseaseName = mentaldiseaseName;
    }

    public String getSureHospital() {
        return sureHospital;
    }

    public void setSureHospital(String sureHospital) {
        this.sureHospital = sureHospital;
    }

    public String getEconomyCode() {
        return economyCode;
    }

    public void setEconomyCode(String economyCode) {
        this.economyCode = economyCode;
    }

    public String getPerficialAdvise() {
        return perficialAdvise;
    }

    public void setPerficialAdvise(String perficialAdvise) {
        this.perficialAdvise = perficialAdvise;
    }

    public String getCardid() {
        return cardid;
    }

    public void setCardid(String cardid) {
        this.cardid = cardid;
    }

    public String getWzd() {
        return wzd;
    }

    public void setWzd(String wzd) {
        this.wzd = wzd;
    }

    public String getRes4() {
        return res4;
    }

    public void setRes4(String res4) {
        this.res4 = res4;
    }

    public String getCreatetime() {
        return createtime;
    }

    public void setCreatetime(String createtime) {
        this.createtime = createtime;
    }

    public String getCreater() {
        return creater;
    }

    public void setCreater(String creater) {
        this.creater = creater;
    }

    public String getQdqxz() {
        return qdqxz;
    }

    public void setQdqxz(String qdqxz) {
        this.qdqxz = qdqxz;
    }

    public int getSelfInjury() {
        return selfInjury;
    }

    public void setSelfInjury(int selfInjury) {
        this.selfInjury = selfInjury;
    }

    public String getRes3() {
        return res3;
    }

    public void setRes3(String res3) {
        this.res3 = res3;
    }

    public String getLockCode() {
        return lockCode;
    }

    public void setLockCode(String lockCode) {
        this.lockCode = lockCode;
    }

    public String getGuardName() {
        return guardName;
    }

    public void setGuardName(String guardName) {
        this.guardName = guardName;
    }

    public String getGuardphone() {
        return guardphone;
    }

    public void setGuardphone(String guardphone) {
        this.guardphone = guardphone;
    }

    public String getKnownCode() {
        return knownCode;
    }

    public void setKnownCode(String knownCode) {
        this.knownCode = knownCode;
    }

    public String getClinicCode() {
        return clinicCode;
    }

    public void setClinicCode(String clinicCode) {
        this.clinicCode = clinicCode;
    }

    public String getSureDate() {
        return sureDate;
    }

    public void setSureDate(String sureDate) {
        this.sureDate = sureDate;
    }

    public String getInputName() {
        return inputName;
    }

    public void setInputName(String inputName) {
        this.inputName = inputName;
    }

    public String getInputTime() {
        return inputTime;
    }

    public void setInputTime(String inputTime) {
        this.inputTime = inputTime;
    }
    public JsjbBaseInfo(){}

    public static List<JsjbBaseInfo> convertData(Context context) {
        List<CD_MENTALDISEASE_BASEINFO> datas = FDbManager.getInstance(context).findAllByWhere(
                CD_MENTALDISEASE_BASEINFO.class, "IS_UPDATE is not 'N'" + "AND CREATEORG='" + NovaApplication.getJgbh() + "'");

        List<JsjbBaseInfo> wbdatas = new ArrayList<JsjbBaseInfo>();
        JsjbBaseInfo wbdata;
        for (CD_MENTALDISEASE_BASEINFO data : datas) {
            wbdata = new JsjbBaseInfo();
            wbdata.setMainSymptom(data.getSYMPTOM());//既往主要症状
            wbdata.setCardid(TextUtils.isEmpty(data.getIDCARD()) ? "" : data.getIDCARD().toUpperCase());// 居民身份证/健康卡号
           if(TextUtils.isEmpty(wbdata.getCardid())&&!TextUtils.isEmpty(data.getARCHIVEID())){
                List<ARCHIVE_BASEINFO> ss=FDbManager.getInstance(context).findAllByWhere(ARCHIVE_BASEINFO.class,"ARCHIVEID='"+data.getARCHIVEID()+"'");
                if(ss.size()>0){
                    if(!ss.get(0).getPOPULATION_TYPE().contains("5")){
                        continue;
                    }
                    wbdata.setCardid(ss.get(0).getIDCARD().toUpperCase());
                }else{
                    wbdata.setCardid("");
                }

            }else{
               List<ARCHIVE_BASEINFO> ss=FDbManager.getInstance(context).findAllByWhere(ARCHIVE_BASEINFO.class,"IDCARD='"+data.getIDCARD()+"'");
               if(ss.size()>0){
                   if(!ss.get(0).getPOPULATION_TYPE().contains("5")){
                       continue;
                   }
               }
           }
            if(!TextUtils.isEmpty(data.getMILD_TROUBLE_FREQUEN())){
                wbdata.setLightAffray(Integer.parseInt(data.getMILD_TROUBLE_FREQUEN()));//轻度滋事次数
            }
           if(!TextUtils.isEmpty(data.getCREATE_DISTU_FREQUEN())){
               wbdata.setCauseTrouble(Integer.parseInt(data.getCREATE_DISTU_FREQUEN()));// 肇事次数
           }
            if(!TextUtils.isEmpty(data.getCAUSE_ACCID_FREQUEN())){
                wbdata.setCauseAccident(Integer.parseInt(data.getCAUSE_ACCID_FREQUEN()));//肇祸次数
            }

            if(!TextUtils.isEmpty(data.getATTEMPT_SUIC_FREQUEN())){
                wbdata.setAttemptedSuicide(Integer.parseInt(data.getATTEMPT_SUIC_FREQUEN()));//自杀未遂次数
            }

            if(data.getOtherDamage_FREQUEN()!=null){
                wbdata.setRes5(data.getOtherDamage_FREQUEN());//其他伤害行为
            }

            wbdata.setCreateorg(data.getCREATEORG());// 创建机构
            wbdata.setCreater(data.getCREATER());// 创建人id CREATED_BY
            if(data.getCREATED_DATE()!=null){
                wbdata.setCreatetime(GlobalConts.datetimeFormat.format(data.getCREATED_DATE()));// 创建时间
            }else{
                wbdata.setCreatetime("");// 创建时间
            }
            if("null".equals(data.getATTEMPT_SUICIDE_NONE())){//无危险行为
                wbdata.setRes2("DM01-11_1");
            }
            wbdata.setOtherSymptom(data.getSYMPTOM_OTHER());//既往主要症状其他
            wbdata.setGuardAddress(data.getGURADIAN_ADDR());//监护人地址
            wbdata.setRelationship(data.getRALATION());//与患者关系
            wbdata.setCommitDutyname(data.getVILLAGE_CONTACTS());//村委会联系人
            wbdata.setCommitDutyphone(data.getVILLAGE_TEL());//村委会电话
            wbdata.setKnowSignname(data.getAGREE_SIGNATURE());//知情同意签字
            wbdata.setKnowSigndate(data.getAGREE_TIME() == null ? "" : GlobalConts.dateFormat.format(data.getAGREE_TIME()));//签字时间
            wbdata.setFriststartAge(data.getFIRST_TIME() == null ? "" : GlobalConts.dateFormat.format(data.getFIRST_TIME()));//初次发病时间
            wbdata.setFristavoidCode(data.getFIRST_TREATMENT_TIME() == null ? "" : GlobalConts.dateFormat.format(data.getFIRST_TREATMENT_TIME()));//首次抗精神病药治疗时间
            wbdata.setSpecialhospNum(data.getHOSPITAL_COUNT());//曾住精神专科医院/综合医院精神专科次数
            wbdata.setMentaldiseaseName(data.getPRESENT_SYMPTOM());//目前诊断情况诊断
            wbdata.setSureHospital(data.getDIAGNOSIS_HOSPITAL());//确诊医院
            wbdata.setEconomyCode(data.getECONOMY());//经济状况
            wbdata.setPerficialAdvise(data.getSPECIALIST_PROPOSAL());//专科医生意见
            wbdata.setRes4(data.getJYQK());//就业情况
            if(!TextUtils.isEmpty(data.getAUTOLESION_FREQUEN())){
                wbdata.setSelfInjury(Integer.parseInt(data.getAUTOLESION_FREQUEN()));//自伤次数
            }
            wbdata.setRes3(data.getHousehold());//户别
            wbdata.setLockCode(data.getLOCK_CONDITION());//既往关锁情况
            wbdata.setGuardName(data.getGUARDIAN_NAME());//监护人姓名
            wbdata.setGuardphone(data.getGURADIAN_PHONE());//监护人电话
            wbdata.setKnownCode(data.getAGREE_MANAGEMENT());//知情同意
            wbdata.setClinicCode(data.getOUTPATIEN());//门诊

            wbdata.setSureDate(data.getDIAGNOSIS_TIME() == null ? "" : GlobalConts.dateFormat.format(data.getDIAGNOSIS_TIME()));//确诊日期
            wbdata.setInputName(data.getDOCTOR_MARK());//医生签名
            wbdata.setInputTime(data.getFILLFORM_TIME() == null ? "" : GlobalConts.dateFormat.format(data.getFILLFORM_TIME()));

            wbdata.setFromType("2");
            wbdata.setUpdatetime(data.getLAST_UPDATE_DATE()==null?"":GlobalConts.datetimeFormat.format(data.getLAST_UPDATE_DATE()));


            String[] arr = GlobalConts.assessIntegrity(wbdata.getCardid(),wbdata.getCreateorg(),wbdata.getCreater(),wbdata.getCreatetime(),wbdata.getInputName());
            wbdata.setWzd(arr[0]);// 完整度
            wbdata.setQdqxz(arr[1]);// 缺项值
            wbdatas.add(wbdata);
        }
        return wbdatas;
    }



}
